(* This function does not check overflow. If argument is too large, this function will return 0.  *)
let rec factorial n = 
    let rec factorial_helper x acc = 
      if (x <= 1) 
          then acc 
          else (factorial_helper (x-1) (acc * x))
    in 
    factorial_helper n 1
;;

let abs i = if i < 0 then -i else i ;;
let fabs i = if i < 0. then -.i else i ;;

let rec pow (b, e) = 
    if e < 0 then
        failwith "pow: invalid argument"
    else
        let rec aux res = function
            | 0 -> res
            | n -> aux (res*b) (n-1)
        in aux 1 e

